package com.ebupt.migu.music.kafka.controller;

import com.ebupt.migu.music.kafka.entity.KafkaMsg;
import com.ebupt.migu.music.kafka.entity.KafkaProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/kafka", produces = MediaType.APPLICATION_JSON_VALUE)
public class KafkaController {

    @Autowired
    private KafkaProducer kafkaProducer;

    @RequestMapping(value = "/send", method = RequestMethod.GET)
    public KafkaMsg send(String msgId, String key, String name){
        System.out.println("send start! ----------------------");
        KafkaMsg kafkaMsg = new KafkaMsg();
        kafkaMsg.setMsgId(msgId);
        kafkaMsg.setKey(key);
        kafkaMsg.setName(name);
        kafkaProducer.sendMsg(kafkaMsg);
        return kafkaMsg;
    }

}
